/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.<br>
 */
package com.ce.pms.system.renovation.web;

import java.util.List;

import com.ce.pms.base.vo.SearchVO;
import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.charge.vo.BusinessCodeVO;
import com.ce.pms.common.service.ISysrefcodeService;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.exception.UILayerException;
import com.ce.pms.system.renovation.service.IRenovateChargeItemConfigService;
import com.ce.pms.system.renovation.vo.RenovateChargeItemConfigVO;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.support.Page;

/**
 * 功能描述：<br>
 * @author 易贤建 创建日期：2008-12-24<br>
 */
public class RegisterItemAction extends PmsBaseAction {
	/**
	 * 装修收费项目
	 */
	private IRenovateChargeItemConfigService renovateChargeItemConfigService = null;

	/**
	 * 功能描述:初始化列表页面<br>
	 * @param searchVO
	 * @param pageSize
	 * @param pageNo
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	public String initList(@Read SearchVO searchVO,
						   @Read(key = "ec_crd",defaultValue="10")	int pageSize,
			               @Read(key = "ec_p", defaultValue="1")	int pageNo){
		searchVO.setPageSize(pageSize);
		searchVO.setPageNo(pageNo);

		Page page = renovateChargeItemConfigService.queryRenovateChargeItemList(searchVO);
		setAttribute("renovateChargeItemConfigs", page.getResult());
		setAttribute("totalRows", Integer.valueOf(String.valueOf(page.getTotalCount())));
		return "list";
	}
	/**
	 * 功能描述: 初始化添加页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	public String initAdd(){
		initBusinessCode();//缓存交易码
		return "add";
	}
	/**
	 * 功能描述:初始化修改页面<br>
	 * @param keyword
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	public String initEdit(@Read(key="keyword")Long keyword){
		RenovateChargeItemConfigVO vo = renovateChargeItemConfigService.getRenovateChargeItemConfigById(keyword);
		setAttribute("configVO", vo);
		initBusinessCode();//缓存交易码
		return "edit";
	}
	/**
	 * 功能描述:添加装修收费项目<br>
	 * @param vo
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	public String add(@Read RenovateChargeItemConfigVO vo){
		vo.setCreator(super.getUserId());
		renovateChargeItemConfigService.add(vo);
		processOption(); //处理按钮类型
		return "result";
	}
	/**
	 * 功能描述:修改装修收费项目<br>
	 * @param vo
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	public String edit(@Read RenovateChargeItemConfigVO vo){
		vo.setModifier(super.getUserId());
		renovateChargeItemConfigService.edit(vo);
		processOption(); //处理按钮类型
		return "result";
	}
	/**
	 * 功能描述:删除装修收费项目<br>
	 * @param vo
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	public void delete(@Read(key="keyword")Long keyword){
		try{
			renovateChargeItemConfigService.delete(keyword);
		}catch(Exception excepiton){
			throw new UILayerException("system:approval_delete_is_reference",UILayerException.FAILURE);
		}
	}

	public void validateItemName(@Read RenovateChargeItemConfigVO vo){
		try{
			renovateChargeItemConfigService.validateItenName(vo);
			super.renderText("true");
		}catch(BusinessException exception){
			String errorMessage = exception.getMessage();
			super.renderText(super.getLocaleMessage(errorMessage));
		}
	}
	/**
	 * 功能描述: 处理页面传过来的按钮类型,页面有保存并新增、保存按钮,页面有按钮类型隐藏表单域<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	private void processOption(){
		String option = getRequest().getParameter("option");
		setAttribute("option", option);
	}
	/**
	 * 功能描述:缓存收入类型的交易码列表<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	private void initBusinessCode(){
		List<BusinessCodeVO> bizCode = renovateChargeItemConfigService.getBusinessCode();
		setAttribute("bizCodes", bizCode);
	}
	public void setRenovateChargeItemConfigService(
			IRenovateChargeItemConfigService renovateChargeItemConfigService) {
		this.renovateChargeItemConfigService = renovateChargeItemConfigService;
	}
	public void setSysrefcodeService(ISysrefcodeService sysrefcodeService) {
		this.sysrefcodeService = sysrefcodeService;
	}
}
